package com.zmn.oms.services.impl.ins;

import com.zmn.oms.model.entity.ins.InsOrderMaster;
import com.zmn.oms.model.entity.ins.InsOrderMasterQuery;
import com.zmn.oms.persistence.interfaces.ins.InsOrderMasterDao;
import com.zmn.oms.services.interfaces.ins.InsOrderMasterService;
import com.zmn.oms.services.interfaces.orderencrypt.InsOrderEncryptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类描述：保险单
 *
 * @author liuying
 * @date 2019/01/23 10:48
 */
@Service
public class InsOrderMasterServiceImpl implements InsOrderMasterService {

    @Resource
    private InsOrderMasterDao insOrderMasterDao;
    @Autowired
    private InsOrderEncryptService insOrderEncryptService;

    @Override
    public List<InsOrderMaster> listInsOrderMasterByOrderId(Long orderId) {
        List<InsOrderMaster> insOrderMasters = insOrderMasterDao.listInsOrderMasterByOrderId(orderId);
        return insOrderEncryptService.batchDecryptInsOrderMaster(insOrderMasters);
    }

    @Override
    public List<InsOrderMaster> listInsOrderMaster(InsOrderMasterQuery insOrderMasterQuery) {
        List<InsOrderMaster> insOrderMasters = insOrderMasterDao.listInsOrderMaster(insOrderMasterQuery);
        return insOrderEncryptService.batchDecryptInsOrderMaster(insOrderMasters);
    }

    @Override
    public void updateInsOrderMasterByKey(InsOrderMaster insOrderMaster) {
        InsOrderMaster insOrderMasterCopy = insOrderEncryptService.encryptInsOrderMaster(insOrderMaster);
        insOrderMasterDao.updateInsOrderMasterByKey(insOrderMasterCopy);
    }

    @Override
    public int insertInsOrderMaster(InsOrderMaster insOrderMaster) {
        InsOrderMaster insOrderMasterCopy = insOrderEncryptService.encryptInsOrderMaster(insOrderMaster);
        int count = insOrderMasterDao.insertInsOrderMaster(insOrderMasterCopy);
        insOrderMaster.setInsMasterId(insOrderMasterCopy.getInsMasterId());
        return count;
    }
}
